package org.example.view;

import javax.swing.*;
import java.awt.*;

public class DemoI extends JFrame {

    private JTable jtable;

    private JScrollPane jsp ;

    public DemoI() throws HeadlessException {
        // 标题 一般书写在第一行
        setTitle("我的第一个界面");
        // 表格有两种实例化写法
        // 1. 仅设置行和列
        // jtable = new JTable(7,5);
        // 2. 设置表头和表数据
        String[] title = {"序号", "姓名", "性别", "职业", "住址", "备注"};
        Object[][] data = {
                {
                        "1", "张三1", "男", "程序员", "陕西商洛", "没有"
                },
                {
                        "2", "张三2", "男", "程序员", "陕西商洛", "没有"
                },
                {
                        "2", "张三2", "男", "程序员", "陕西商洛", "没有"
                },
                {
                        "2", "张三2", "男", "程序员", "陕西商洛", "没有"
                },
                {
                        "2", "张三2", "男", "程序员", "陕西商洛", "没有"
                },
                {
                        "2", "张三2", "男", "程序员", "陕西商洛", "没有"
                },
                {
                        "2", "张三2", "男", "程序员", "陕西商洛", "没有"
                },
                {
                        "2", "张三2", "男", "程序员", "陕西商洛", "没有"
                },
                {
                        "2", "张三2", "男", "程序员", "陕西商洛", "没有"
                },
                {
                        "2", "张三2", "男", "程序员", "陕西商洛", "没有"
                },
                {
                        "2", "张三2", "男", "程序员", "陕西商洛", "没有"
                },
                {
                        "2", "张三2", "男", "程序员", "陕西商洛", "没有"
                },
                {
                        "2", "张三2", "男", "程序员", "陕西商洛", "没有"
                },
                {
                        "2", "张三2", "男", "程序员", "陕西商洛", "没有"
                },
                {
                        "2", "张三2", "男", "程序员", "陕西商洛", "没有"
                },
                {
                        "2", "张三2", "男", "程序员", "陕西商洛", "没有"
                },
                {
                        "2", "张三2", "男", "程序员", "陕西商洛", "没有"
                },
                {
                        "2", "张三2", "男", "程序员", "陕西商洛", "没有"
                },
                {
                        "2", "张三2", "男", "程序员", "陕西商洛", "没有"
                }
        };
        jtable = new JTable(data, title);
        jsp = new JScrollPane(jtable);
        add(jsp);
        // 设置尺寸和位置
        int x = 500;
        int y = 400;
        int width = 450;
        int height = 200;
        setBounds(x, y, width, height);
        // 设置窗体剧中显示
        setLocationRelativeTo(null);
        // 设置点击关闭时释放内存
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        // 配置显示
        setVisible(true);
    }

    public static void main(String[] args) {
        new DemoI();
    }
}
